package com.yingside.io.io;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class TestByteArrayOutputStream {
    public static void main(String[] args) {
        FileInputStream fis = null;
        //字节数组输出流
        ByteArrayOutputStream baos = null;
        try {
            fis = new FileInputStream("images/TestJFram.txt");
            baos = new ByteArrayOutputStream();

            int n = -1;
            while((n = fis.read()) != -1){
                baos.write(n);
            }


            byte[] bytes = baos.toByteArray();
            System.out.println(bytes.length);

            String s = baos.toString();
            System.out.println("s = " + s);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                baos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
